using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace simulate_control.Repositories
{
	#region using
	using simulate_control.Models;
	#endregion
	public class SystemSetupRepository
	{
		public static List<SystemSetup> SelectAll()
		{
			return DataContext.Instance.SystemSetup.ToList();
		}

		public static SystemSetup SelectByID(int id)
		{
			return DataContext.Instance.SystemSetup.FirstOrDefault(item => item.ID == id );
		}

		public static bool Insert(SystemSetup obj)
		{
			try
			{
				DataContext.Instance.SystemSetup.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int id)
		{
			try
			{
				var delitem = DataContext.Instance.SystemSetup.FirstOrDefault(item => item.ID == id );
				DataContext.Instance.SystemSetup.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<SystemSetup> RetrieveByID(int id)
		{
			return (from item in DataContext.Instance.SystemSetup where  item.ID == id  select item).ToList();
		}

	}
}